﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP_RORZE_ORDER.BizLogic;
using ERP_RORZE_ORDER.Common;
using ERP_RORZE_ORDER.Common.ValueObject;
using ERP_RORZE_TOOL.Common;
using ERP_RORZE_TOOL.DBAccess;

namespace ERP_RORZE_ORDER.OrderObject.UserControls
{
    public partial class ucPrint : DevExpress.XtraEditors.XtraUserControl
    {
        
        public ucPrint()
        {
            InitializeComponent();
            BindDataOrder();

        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            if (!Utilities.IsNullOrEmpty(cmbOrder.SelectedValue) || cmbOrder.SelectedItem != cmbOrder.Items[0])
            {
                ucView view = new ucView(cmbOrder.SelectedValue.ToString());
                panelBottom.Controls.Clear();
                panelBottom.Controls.Add(view);
                view.Dock = DockStyle.Fill;
            }
            Cursor.Current = Cursors.Default;

            //Cursor.Current = Cursors.WaitCursor;
            //if (!Utilities.IsNullOrEmpty(cmbOrder.SelectedValue) || cmbOrder.SelectedItem != cmbOrder.Items[0])
            //{
            //    ucCrystalcs view = new ucCrystalcs(cmbOrder.SelectedValue.ToString());
            //    panelBottom.Controls.Clear();
            //    panelBottom.Controls.Add(view);
            //    view.Dock=DockStyle.Fill;
            //}
            //Cursor.Current = Cursors.Default;
        }
        
        private void BindDataOrder()
        {
            OrderHelper helper = new OrderHelper(new Order());
            DataTable dt = helper.GetAll();
            DataRow row = dt.NewRow();

            row[OrderConstants.Entities.Order.FieldName.OrderID] = null;
            dt.Rows.InsertAt(row, 0);

            cmbOrder.DataSource = dt;
            cmbOrder.DisplayMember = OrderConstants.Entities.Order.FieldName.OrderID;
            cmbOrder.ValueMember = OrderConstants.Entities.Order.FieldName.OrderID;
        }

        private void btExport_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            ucGridViewPrint grid = new ucGridViewPrint(cmbOrder.SelectedValue.ToString());
            panelBottom.Controls.Clear();
            panelBottom.Controls.Add(grid);
            grid.Dock = DockStyle.Fill;
            Cursor.Current = Cursors.Default;
        }

    }
}
